package rsj.api.product;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.TableNode;
import common.util.BoxUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.context.ApplicationContextUtil;
import rsj.domain.ProductPageQuery;
import rsj.service.ProductService;
import rsj.util.PaginationData;
@RestController
public class GetProdQuery extends BaseLink {

    //private static final ProductService productService = ProductService.getInstance();

    @Override
    @RequestMapping(value = "rsj_prod_list")
    public Box executeLink(Box in) {
        MapNode data = in.getMapNode("data");
        ProductPageQuery query = buildPageQuery(data);
        ProductService productService = ApplicationContextUtil.getBean(ProductService.class);
        PaginationData<TableNode> paginationData = productService.getPage(query);

        MapNode outData = new MapNode();
        outData.putNode("Prod_List", paginationData.getDataList().toJson());
        outData.putNode("Prod_Count", String.valueOf(paginationData.getTotalCount()));

        return BoxUtil.successBoxToData(in, "获取用户查询列表信息！", outData);
    }

    private ProductPageQuery buildPageQuery(MapNode data) {
        ProductPageQuery query = new ProductPageQuery();
        query.setIsProdQuery();// 设置是全量查询

        if (null == data) {
            return query;
        }

        query.setPageCount(data.getValueIntDef("Page_Count", 0));
        query.setPageSize(data.getValueIntDef("Page_Size", 0));
        query.setProdName(data.getValue("Query_Key"));
        query.setOrgId(data.getValue("Org_Id"));
        query.setProdType(data.getValue("Prod_Type"));
        return query;
    }

}
